Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
ahooks is a high-quality and reliable React Hooks library that provides a comprehensive set of hooks to enhance your React development experience. It includes a wide range of hooks for state management, side effects, lifecycle, and more.
State Management
The useBoolean hook provides a simple way to manage boolean state with additional methods to toggle, set true, and set false.
import { useBoolean } from 'ahooks';
function App() {
const [state, { toggle, setTrue, setFalse }] = useBoolean(false);
return (
<div>
<p>State: {state.toString()}</p>
<button onClick={toggle}>Toggle</button>
<button onClick={setTrue}>Set True</button>
<button onClick={setFalse}>Set False</button>
</div>
);
}
Side Effects
The useDebounceEffect hook allows you to debounce side effects, which is useful for scenarios like search input where you want to delay the execution of a function.
import { useDebounceEffect } from 'ahooks';
function App() {
const [value, setValue] = useState('');
useDebounceEffect(() => {
console.log('Debounced value:', value);
}, [value], { wait: 500 });
return (
<input value={value} onChange={(e) => setValue(e.target.value)} />
);
}
Lifecycle
The useMount hook runs a function once when the component is mounted, similar to componentDidMount in class components.
import { useMount } from 'ahooks';
function App() {
useMount(() => {
console.log('Component mounted');
});
return <div>Check the console</div>;
}
react-use is a collection of essential React Hooks that provides a wide range of hooks for state management, lifecycle, sensors, and more. It is similar to ahooks in terms of the variety and utility of hooks offered, but it has a different set of hooks and may have different implementations for similar functionalities.
usehooks-ts is a collection of React hooks written in TypeScript. It offers a variety of hooks for state management, side effects, and more. Compared to ahooks, usehooks-ts is specifically designed for TypeScript users, providing type-safe hooks out of the box.
react-hooks-library is another collection of reusable React hooks. It focuses on providing hooks for common use cases like state management, side effects, and lifecycle methods. While it offers similar functionalities to ahooks, it may have a smaller set of hooks and different API designs.
$ npm install --save ahooks
# or
$ yarn add ahooks
# or
$ pnpm add ahooks
# or
$ bun add ahooks
import { useRequest } from 'ahooks';
$ git clone git@github.com:alibaba/hooks.git
$ cd hooks
$ pnpm run init
$ pnpm start
Open your browser and visit http://127.0.0.1:8000
We welcome all contributions, please read our CONTRIBUTING.MD first, let's build a better hooks library together.
Thanks to all the contributors:
FAQs
react hooks library
We found that ahooks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.